package UnitTest;

import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;

/**
 * @Auther: Administrator
 * @Date: 2019/12/8/008 22 08
 * @Description:
 */
public class Piped {

    public static void main(String[] args) throws Exception{
        PipedWriter out = new PipedWriter();
        PipedReader in = new PipedReader();
        out.connect(in);
        Thread thread = new Thread(new Print(in), "print");
        thread.start();
        int reveive = 0;
        try {
            while ((reveive=System.in.read())!=-1){
                out.write((char)reveive);
            }
        } finally {
            out.close();
        }
    }
    

    static  class Print implements Runnable{
        private static PipedReader in;
        public Print(PipedReader reader){
            in = reader;
        }
        @Override
        public void run() {
            int reciver = 0 ;
            try {
                while ((reciver=in.read())!=-1){
                    System.out.print((char)reciver);
                }
                System.out.println();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
